﻿
#include "stdafx.h"
#include "BackGDC.h"

BackGDC::BackGDC()
{
	m_iWidth = 800;
	m_iHeight = 600;
	m_bIsDraw = 0;
	HDC hDeskTopDC = GetDC(NULL);
	m_hdcBK = CreateCompatibleDC(hDeskTopDC);
	m_hBitmap = CreateCompatibleBitmap(hDeskTopDC, m_iWidth, m_iHeight);
	m_hOldBmp = (HBITMAP)SelectObject(m_hdcBK, m_hBitmap);
	ReleaseDC(NULL, hDeskTopDC);
}

BackGDC::BackGDC(int _width, int _height)
{
	m_iWidth = _width;
	m_iHeight = _height;
	m_bIsDraw = 0;
	HDC hDeskTopDC = GetDC(NULL);
	m_hdcBK = CreateCompatibleDC(hDeskTopDC);
	m_hBitmap = CreateCompatibleBitmap(hDeskTopDC, m_iWidth, m_iHeight);
	m_hOldBmp = (HBITMAP)SelectObject(m_hdcBK, m_hBitmap);
	ReleaseDC(NULL, hDeskTopDC);
}
BackGDC::BackGDC(HWND hWnd, int _width, int _height, HBITMAP hBitmap)
{
	m_iWidth = _width;
	m_iHeight = _height;
	m_bIsDraw = 0;
	HDC hDeskTopDC = GetDC(hWnd);
	m_hdcBK = CreateCompatibleDC(hDeskTopDC);
	m_hBitmap = hBitmap;
	m_hOldBmp = (HBITMAP)SelectObject(m_hdcBK, m_hBitmap);
	ReleaseDC(hWnd, hDeskTopDC);
}

BackGDC::~BackGDC()
{
	SelectObject(m_hdcBK, m_hOldBmp);
	DeleteObject(m_hBitmap);
	DeleteDC(m_hdcBK);
}
void BackGDC::DrawItem(void (*Draw)(HDC hdc))
{
	m_bIsDraw = 1;
	Draw(m_hdcBK);
}
